from django.db import models
from django.db.models import CASCADE


# Create your models here.


class HeadlineClassify(models.Model):
    name = models.CharField(verbose_name="类名", max_length=200)

    class Meta:
        db_table = "tb_hline_classify"
        verbose_name = "头条分类表"
        verbose_name_plural = verbose_name


class HeadlineTag(models.Model):
    name = models.CharField(verbose_name="标签名", max_length=200)

    class Meta:
        db_table = "tb_hline_tag"
        verbose_name = "头条标签表"
        verbose_name_plural = verbose_name


class HeadlineText(models.Model):
    title = models.CharField(max_length=200, verbose_name="标题")
    # TODO 外键
    # author_id = models.IntegerField(verbose_name="作者ID")
    img = models.CharField(max_length=200, verbose_name="图片", null=True)
    c_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    intro = models.CharField(max_length=200, verbose_name="简介")
    detail = models.TextField(verbose_name="详情")
    classify_id = models.ForeignKey(HeadlineClassify, verbose_name="类别ID", on_delete=CASCADE, null=True)
    tag_id = models.ForeignKey(HeadlineTag, verbose_name="标签ID", on_delete=CASCADE, null=True)

    class Meta:
        db_table = "tb_hline_t"
        verbose_name = "头条表"
        verbose_name_plural = verbose_name


class HeadlineComment(models.Model):
    user_id = models.IntegerField(verbose_name="用户ID")
    parents_id = models.ForeignKey("self", on_delete=CASCADE, verbose_name="评论父ID", null=True)
    comment = models.CharField(verbose_name="评论内容", max_length=200)
    hl_id = models.ForeignKey(HeadlineText, verbose_name="新闻ID", on_delete=CASCADE)

    class Meta:
        db_table = "tb_hline_c"
        verbose_name = "头条评论表"
        verbose_name_plural = verbose_name
